package cn.wolfcode.crm.web.controller;
/**
 * Created by 10797 on 2018/7/14.
 */

import cn.wolfcode.crm.query.PaymentBillQueryObject;
import cn.wolfcode.crm.service.IPaymentBillService;
import cn.wolfcode.crm.service.IPaymentResultService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @program: crm
 * @description: 缴费单组件
 * @author: Mr.chen
 * @create: 2018-07-14 10:36
 **/
@Controller
@RequestMapping("paymentBill")
public class PaymentBillController {

    @Autowired
    private IPaymentBillService paymentBillService;
    @Autowired
    private IPaymentResultService paymentResultService;

    @RequestMapping("")
    public String list(){
        return "/paymentBill/list";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(PaymentBillQueryObject qo){
        return paymentBillService.query(qo);
    }

    /*
    * 缴费提交的方法
    * id:当前保单的编号
    * payWayId:支付的方式
    * beginDate:保单的起保日期
    * */
    @RequestMapping("submit")
    @ResponseBody
    public JsonResult submit(Long id, Long payWayId, @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginDate){
        try{
            if(id != null){
                paymentResultService.add(id,payWayId,beginDate);
            }
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult("缴费失败");
        }
        return new JsonResult();

    }

}
